program main
integer a(80),p1,p2,p3,p4,u1,u2
logical m,s
read(*,*)n
m=.false.
do 10 while(.not.m)
    write(*,*)'input p1,p2,p3,p4'
    read(*,*)p1,p2,p3,p4
    m=s(p1,p2,p3,p4)
10 continue
do 20 i=1,n
    a(i)=i
    !real(sui())
20 continue
write(*,*)(a(i),i=1,n)
u1=p4-p3
u2=p2-p1
do 30 j=0,u1
    do 40 i=n,p1,-1
        a(i+1)=a(i)
    40 continue
    n=n+1
30 continue
do 50 i=0,u1
    a(p1+i)=a(p3+i+u1+1)
50 continue
print*,(a(i),i=1,n)
if(u2.GE.u1)then
    do 60 j=1,u2-u1
        do 70 i=n,p3+u1+1,-1
        a(i+1)=a(i)
    70 continue
    60 continue
    do 80 i=0,u2
    a(p3+u1+1+i)=a(p1+u1+i)
    80 continue
else
    do 90 j=1,u1-u2
        do 100 i=n,p3+u1+1,-1
        a(i-1)=a(i)
    100 continue
    90 continue
    do 110 i=0,u2
    a(p3+u1+1+i)=a(p1+u1+i)
    110 continue
end if
print*,(a(i),i=1,n)
end

function s(p1,p2,p3,p4)
    integer p1,p2,p3,p4,h
    logical s
    h=1
    if(h.LE.p1.and.p2.GT.p1.and.p3.GT.p2.and.p4.GT.p3.and.p4.LT.20)then
        s=.true.
    else
        s=.false.
    end if
end function
function sui()
    real :: x
    call random_seed ()
    call random_number (x)
    sui=x*100
end function

